<?php

namespace app\index\dao;

use app\common\model\LawsuitComment;
use ShidianUtil\Thinkphp\Dao\DaoTrait;
use think\Collection;

/**
 * LawsuitCommentDao 数据访问对象
 * Class LawsuitCommentDao
 * @package app\index\dao
 * @method LawsuitComment findByPK(?int $id, $field = true)
 * @method \think\Collection selectAll(?int $page, ?int $page_size, $field = true)
 * @method LawsuitComment insertActive(array $params, array $allow_field = [])
 * @method LawsuitComment updateActive(LawsuitComment $model, array $params, array $allow_field = [])
 * @method LawsuitComment findAndUpdateActive(int $id, array $params, array $allow_field = [])
 * @method LawsuitComment updateActiveByClosure(\Closure $closure, array $params, array $allow_field = [])
 * @method void deleteModel(LawsuitComment $model)
 * @method void deleteById(int|array|\Closure $id, bool $force = false)
 * @link https://www.kancloud.cn/manual/thinkphp6_0/1037579
 * @link https://www.kancloud.cn/manual/think-orm/1257998
 * @link https://www.kancloud.cn/thinkphp/master-database-and-model/265551
 */
class LawsuitCommentDao
{
    use DaoTrait;

    /**
     * @var LawsuitComment
     */
    private $baseModel;

    /**
     * LawsuitCommentDao constructor.
     */
    public function __construct()
    {
        $this->baseModel = LawsuitComment::class;
    }

    public function selectCommentsLawsuit($categoryId): Collection
    {
        $times = [
            '4分钟前', '10分钟前', '13分钟前', '16分钟前', '19分钟前', '20分钟前', '23分钟前', '26分钟前', '30分钟前', '32分钟前', '40分钟前'
        ];

        return LawsuitComment::where('categoryId', $categoryId)
            ->withAttr(['timeStr' => function ($value, $data) use (&$times) {
                if (empty($times)) {
                    return '';
                }
                return array_shift($times);
            }])
            ->append(['headImg', 'timeStr'])
            ->hidden(['headImgUrl'])
            ->order('created', 'DESC')
            ->select();
    }

}
